package com.group.app.example.repository;

import com.group.app.example.domain.FieldNodeModel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Map;


@Repository
public interface FieldNodeRepository extends JpaRepository<FieldNodeModel, String> {

    @Query(value = "SELECT\n" +
            "code_link || '>' || code AS code_link,\n" +
            "parent_link || '>' || NAME AS parent_link,\n" +
            "NAME,\n" +
            "code \n" +
            "FROM\n" +
            "field_node \n" +
            "WHERE\n" +
            "code != 1 \n" +
            "AND is_node = FALSE\n",nativeQuery = true)
    List<Map<String,Object>> getAllNode();

//    @Modifying
//    @Query(value = "insert into field_node(id,parent_code," +
//            "code_link,name,describe,active_date,node_order,create_time,update_time," +
//            "update_user,create_user,parent_name,parent_link) values(?1,?2,?3,?4,?5,?6,?7,?8,?9,?10,?11,?12,?13)",nativeQuery = true)
//    int insertNode(String id,Integer parentCode,
//                   String codeLink,String name,
//                   String describe,);

//    @Query(value =  "SELECT \n" +
//                    "* " +
//                    "FROM \n" +
//                    "(" +
//                    "SELECT \n" +
//                    "arr [ 2 ] AS FIRST, " +
//                    "arr [ 3 ] AS SECOND, " +
//                    "arr [ 4 ] THREE, " +
//                    "field_name, " +
//                    "field_type " +
//                    "FROM " +
//                    "(SELECT id, string_to_array( parent_link, '>' ) arr FROM field_node ) fwn\n" +
//                    "INNER JOIN field_station fs ON fwn.id = fs.id ) A ",nativeQuery = true)
//    List<Map<String,Object>> queryLabelInfo(Specification<SearchVo> spec, Pageable pageable);




//    countQuery ="SELECT \n" +
//            "count(*) " +
//            "FROM" +
//            "(" +
//            "SELECT /n" +
//            "arr [ 2 ] AS FIRST," +
//            "arr [ 3 ] AS SECOND," +
//            "arr [ 4 ] AS THREE," +
//            "field_name,"+
//            "field_type \n " +
//            "FROM " +
//            "(SELECT code, string_to_array( parent_link, '>' ) arr FROM field_node ) fwn\n" +
//            "INNER JOIN field_station fs ON fwn.code = fs.node_id ) A " +
//            "WHERE 1 = 1 " +
//            "and if(:name != '',field_name like :name,1 = 1)" +
//            "and if(:type != '',field_type like :type,1 = 1)",
}
